﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class OfflineScans : System.Web.UI.Page
{
    private int _count = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["userObject"] == null)
            {
                Response.Redirect("Default.aspx", false);
            }
            else
            {
                ProxyWrapper.UserProxy.UserDetails _objUser = ((ProxyWrapper.UserProxy.UserDetails)Session["UserObject"]);
                ProxyWrapper.ScansServiceWrapper _wrp = new ProxyWrapper.ScansServiceWrapper();
                ProxyWrapper.ScansProxy.SearchParams _param = new ProxyWrapper.ScansProxy.SearchParams();
                _param.ClienId = _objUser.ClientId;
                _param.DeviceIdsList = Request["d"] != null ? Request["d"].ToString() : null;
                _param.FromDate = Request["sd"] != null ? Request["sd"].ToString() : null;
                _param.FromTime = Request["st"] != null ? Request["st"].ToString() : null;
                _param.HashCode = _objUser.HashCode;
                _param.ServiceIdsList = Request["s"] != null ? Request["s"].ToString() : null;
                // 
                string studentNum = Request["q"] != null ? Request["q"].ToString() : null;
                int stuNum = 0;
                if (int.TryParse(studentNum, out stuNum) && stuNum > 0)
                {
                    _param.StudentIdNumber = stuNum;
                }
                else
                {
                    _param.StudentName = studentNum;
                }

                _param.ToDate = Request["ed"] != null ? Request["ed"].ToString() : null;
                _param.ToTime = Request["et"] != null ? Request["et"].ToString() : null;
                _param.UsersList = Request["u"] != null ? Request["u"].ToString() : null;
                List<ProxyWrapper.ScansProxy.Scans> _lstScan = _wrp.ListScans(_param);
                if (_lstScan != null && _lstScan.Count > 0)
                {

                    _lstScan = _lstScan.Where(m => m.ServiceSubType == "ondevicedatabase" || m.ServiceSubType == "ondevicerecord").ToList<ProxyWrapper.ScansProxy.Scans>();
                    _count = _lstScan.Count;
                    lstvwScans.DataSource = _lstScan;
                    lstvwScans.DataBind();

                }
                //_lstScan[0].
            }
        }
        catch (Exception ex)
        {

            throw;
        }
    }
    internal string GetName(string fname, string lname)
    {
        if (!string.IsNullOrWhiteSpace(fname) && !string.IsNullOrWhiteSpace(lname))
            return fname + " " + lname;
        else if (!string.IsNullOrWhiteSpace(fname))
            return fname;
        else if (!string.IsNullOrWhiteSpace(lname))
            return lname;
        else
            return " ";
    }
    internal string GetCount()
    {
        if (_count > 0)
            return "Showing 1 - " + _count.ToString() + " of " + _count.ToString() + " scans.";
        else
            return " ";


    }
    internal string GetValidityImage(int code)
    {
        switch (code)
        {
            case 1:
                return "Images/red.jpg";
            case 2:
                return "Images/green.jpg";
            case 3:
                return "Images/brown.jpg";
            case 4:
                return "Images/yellow.jpg";
            default:
                return "Images/red.jpg";
        }
    }
}